package demo01.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhtt on 2016/10/11.
 */
public class JsonResponse implements Serializable{

    private boolean success=true;

    private String message="";

    private Object data;

    private JsonResponse() {}

    public static JsonResponse success(Object data){
        return new JsonResponse(data);
    }

    public static JsonResponse message(String message){
        JsonResponse jsonResponse=new JsonResponse();
        jsonResponse.setMessage(message);
        return jsonResponse;
    }

    public static JsonResponse page(List<?> data,Integer total){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("total",total);
        map.put("rows",data);
        return new JsonResponse(map);
    }

    public static JsonResponse error(String message){
        return new JsonResponse(false,message);
    }

    public JsonResponse addMessage(String message){
        this.message=message;
        return this;
    }

    private JsonResponse(Object data){
        this.data=data;
    }

    private JsonResponse(boolean success, String message){
        this.message=message;
        this.success=false;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
